﻿using Common;
using InstallWizard.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace InstallWizard
{
    public partial class Page1 : Form
    {
        /// <summary>
        /// 供其他页面调用的应用信息
        /// </summary>
        AppInfo appInfo;        
        string configFile = "wizard.config";
        string pkgFilename = "files.pkg";

      
        public Page1()
        {
            InitializeComponent();
        }
        #region 单独不现实窗体关闭按钮
        private const int CP_NOCLOSE_BUTTON = 0x200;
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams myCp = base.CreateParams;
                myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
                return myCp;
            }
        } 
        #endregion
        private void Page1_Load(object sender, EventArgs e)
        {
        }
        private void Page1_Shown(object sender, EventArgs e)
        {
            //从配置文件中装入产品信息-->给软件提示

            if (!File.Exists(pkgFilename) || !File.Exists(configFile))
            {
                MessageBox.Show("没找到软件包！请确认该软件包的完整性！", "致命错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }

            appInfo = DAL.FileIO.ReadConfigFile(configFile, out List<AppFileInfo> appFileList);
            lbTitle.Text = $"欢迎使用{appInfo.AppName} {appInfo.AppVer}安装向导";
            Text = $"{appInfo.AppName} {appInfo.AppVer}安装向导";
            string comment = $"这个向导将指引你完成 {appInfo.AppName} {appInfo.AppVer} 的安装进程。";
            comment += "\r\n在开始安装之前，建议先关闭其他所有应用程序。这将允许安装程序更新必须的系统文件，而不需要重新启动你的计算机。";
            comment += $"\r\n如果您安装过本软件的早期版本，将会升级到最新的 {appInfo.AppVer} 版本。";
            comment += "\r\n点击[下一步(N)]继续。";
            txtComment.Text = comment;
            picLogo.Load(appInfo.AppLogoFileName);

            txtDesc.Text = appInfo.AppDesc;
        }
        private void BtnNext_Click(object sender, EventArgs e)
        {
            
            this.Hide();
            Form[] pages = Tag as Form[];
            pages[1].Show();
        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();

        }

       
        private void Page1_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

       
    }
}
